import {
	Button,
	Collapse,
	Form,
	Row,
	Col,
	Input,
	Select,
	DatePicker,
	InputNumber,
	TreeSelect,
	message,
	Upload,
	Spin,
} from 'antd'
import React, {useState, useEffect} from 'react'
import {history, connect, useModel} from 'umi'
import moment from 'moment'
import type {UploadFile} from 'antd/es/upload/interface'
import styles from './index.less'
import common from '@/assets/common/css/index.less'
import Answer from './components/Answer'
import BidOpeningRecord from './components/BidOpeningRecord'
import {getDict} from '@/service/common/dict'
import {getGenerateNumber, getOnlydept} from '@/service/common'
import {translateDataToTree} from '@/utils/common'
import Modal from '@/components/Modal'
import {
	addSupplierbidding,
	editSupplierbidding,
	supplierbiddingInfo,
} from '@/service/supplier/supplierbidding'
import {getPublicDownloadUrl, uploadFileUrl} from '@/service/common/upload'
import {getUrlData, getUrls} from './components/data'
import CustomUpload from '@/components/Upload'
import OtherUpload from './components/OtherUpload'
import OperationRecord from '@/components/OperationRecord'

const {Panel} = Collapse
const {TextArea} = Input
const {Option} = Select

const fieldNames = {
	label: 'name',
	value: 'id',
	id: 'id',
	pId: 'parentId',
}

const add = (props: {
	location: {query: any}
	user: {orgId: string | number; userName: string}
}) => {
	const {query} = props.location
	const {initialState} = useModel('@@initialState')
	const {fileName} = initialState || {}
	const [type, setType] = useState<string>()
	const [projectForm] = Form.useForm()
	const [bidEvaluationForm] = Form.useForm()
	const [calibrationForm] = Form.useForm()
	const [accountForm] = Form.useForm()
	const [bidAbandonmentForm] = Form.useForm()
	// 字典数据
	const [dictData, setDictData] = useState<any>({})
	const [deptSource, setDeptSource] = useState<any[]>([])
	// 投标应答数据
	const [answerData, setAnswerData] = useState<any[]>([])
	// 开标记录数据
	const [bidOpeningData, setBidOpeningData] = useState<any[]>([])
	const [draftType, setDraftType] = useState(false)
	const [isModalOpen, setIsModalOpen] = useState(false)
	const [formData, setFormData] = useState<any>({})
	const [projectStatus, setProjectStatus] = useState<string>('1')
	const [enclosureList, setEnclosureList] = useState<any[]>([])
	const [fileList, setFileList] = useState<UploadFile[]>([])
	const [otherFileList, setOtherFileList] = useState<UploadFile[]>([])
	const [otherEvaluationUrl, setOtherEvaluationUrl] = useState<UploadFile[]>(
		[],
	)
	const [otherWinningUrl, setOtherWinningUrl] = useState<UploadFile[]>([])
	const [urlData, setUrlData] = useState<any>({})
	const [loading, setLoading] = useState(false)
	const [btnLoading, setBtnLoading] = useState(false)
	const [departmentData, setDepartmentData] = useState<any>({})

	const callBack = (value: string | number, key: any) => {
		const data = {...urlData}
		data[value] = key
		setUrlData(data)
	}
	/** 获取上级部门数据 */
	const onListFun = () => {
		getOnlydept({merchantId: props.user.orgId}).then((res: any) => {
			if (res.data.length) {
				const list = translateDataToTree(res.data)
				setDeptSource(list as any)
			}
		})
	}
	useEffect(() => {
		onListFun()
	}, [props.user.orgId])

	useEffect(() => {
		// 初始化字典数据
		getDict(
			{
				dictKeys: [
					'ZC_GYS',
					'JC_GYS',
					'CZ_GYS',
					'SP_GYS',
					'DYY_GYS',
					'CS_GYS',
					'Project_Status',
					'Project_Bid_Section',
					'Enterprise_Nature',
					'Agency_Business',
					'Cooperation_Mode',
					'Business_Model',
					'Company_Type',
					'Channel_Type',
					'Settlement_Cycle',
					'Business_Situation',
					'Term_Payment',
					'Invoicing_Tax_Rate',
					'Category',
					'SP_Settlement_Method',
					'CS_Settlement_Method',
				],
			},
			(res: any) => {
				setDictData(res)
			},
		)
	}, [])

	useEffect(() => {
		if (projectStatus === '7') {
			bidAbandonmentForm.setFieldsValue({exceptionType: 1})
		} else if (projectStatus === '8') {
			bidAbandonmentForm.setFieldsValue({exceptionType: 2})
		}
	}, [projectStatus])

	useEffect(() => {
		// 获取详情数据
		if (query?.id) {
			setLoading(true)
			supplierbiddingInfo(query?.id)
				.then((res: any) => {
					setLoading(false)
					if (res?.success) {
						const {data} = res

						const newAnswerList = data?.answerList || []
						const newRecordList: any = data?.recordList || []
						const url = getUrls(data)?.filter((item) => item !== 0)
						const answerUrlList = data?.answerList?.map(
							(item: {biddingFileUrl: string}) =>
								Number(item?.biddingFileUrl),
						)
						let recordUrlList: number[] = []
						data?.recordList?.forEach(
							(item: {priceFileUrl: string}) => {
								const urls = item?.priceFileUrl
									?.split(',')
									.map(Number)
								recordUrlList = recordUrlList.concat(urls)
							},
						)

						const newUrlData = getUrlData(data)
						setUrlData(newUrlData)
						const urls = [
							...url,
							...answerUrlList,
							...recordUrlList,
						]
						if (urls?.length) {
							getPublicDownloadUrl(urls)
								.then((result: any) => {
									setEnclosureList(result?.data)
									if (result?.data) {
										const arr: any = []
										const otherList: any = []
										const otherEvaluation: any = []
										const otherWinning: any = []
										result?.data?.forEach(
											(item: {
												targetAttr: number
												id: any
												filename: any
												url: any
											}) => {
												const newData = {
													uid: item?.id,
													name: item?.filename,
													url: item?.url,
												}
												if (item?.targetAttr === 1) {
													arr.push(newData)
												} else if (
													item?.targetAttr === 5
												) {
													otherList.push(newData)
												} else if (
													item?.targetAttr === 9
												) {
													otherEvaluation.push(
														newData,
													)
												} else if (
													item?.targetAttr === 13
												) {
													otherWinning.push(newData)
												}
												data.answerList?.forEach(
													(
														answerListItem: {
															biddingFileUrl: string
														},
														index: number,
													) => {
														if (
															item?.id ===
															Number(
																answerListItem?.biddingFileUrl,
															)
														) {
															newAnswerList[
																index
															].imgHref =
																item?.url
														}
													},
												)
												data.recordList?.forEach(
													(
														answerListItem: {
															priceFileUrl: string
														},
														index: number,
													) => {
														newRecordList[
															index
														].imgHrefs =
															newRecordList[index]
																.imgHrefs || []
														if (
															answerListItem?.priceFileUrl?.includes(
																item?.id,
															)
														) {
															newRecordList[
																index
															].imgHrefs.push(
																item,
															)
														}
													},
												)
											},
										)
										setFileList(arr)
										setOtherFileList(otherList)
										setOtherEvaluationUrl(otherEvaluation)
										setOtherWinningUrl(otherWinning)
										projectForm.setFieldsValue({
											biddingDocumentUrl: arr,
										})
									}
								})
								.catch((err: any) => {
									message.error(err)
								})
						}
						setProjectStatus(data?.projectStatus)
						projectForm.setFieldsValue({
							...data,
							createArchivesTime: data?.createArchivesTime
								? moment(data?.createArchivesTime)
								: '',
							bidOpeningTime: data?.bidOpeningTime
								? moment(data?.bidOpeningTime)
								: '',
							biddingDocumentUrl: [],
						})
						bidEvaluationForm.setFieldsValue({
							...data,
							bidEvaluationTime: data?.bidEvaluationTime
								? moment(data?.bidEvaluationTime)
								: '',
						})
						calibrationForm.setFieldsValue({
							...data,
							bidWinningIssueDate: data?.bidWinningIssueDate
								? moment(data?.bidWinningIssueDate)
								: '',
						})
						accountForm.setFieldsValue(data)
						bidAbandonmentForm.setFieldsValue({
							...data,
							bidAbandonmentSupplierId:
								data?.bidAbandonmentSupplierId ||
								data?.bidWinningSupplierId,
						})
						setAnswerData(newAnswerList)
						setBidOpeningData(data.recordList)
						setDepartmentData({
							leadingDeptId: res?.data?.leadingDeptId,
							purchaseDeptId: res?.data?.purchaseDeptId,
						})
						projectForm.setFieldsValue({
							leadingDeptId: res?.data?.leadingDeptName,
							purchaseDeptId: res?.data?.purchaseDeptName,
						})
					}
				})
				.catch((err) => {
					message.error(err)
					setLoading(false)
				})
		} else {
			projectForm.setFieldsValue({
				projectStatus: '1',
				createArchivesPerson: props?.user?.userName,
			})
			getGenerateNumber('ZTB').then((res: any) => {
				projectForm.setFieldsValue({biddingCode: res.data})
			})
		}
	}, [query, projectForm])

	// 根据路由判断当前页面状态
	useEffect(() => {
		const hrefs = window.location.href
		if (hrefs.includes('view')) {
			setType('view')
		} else if (hrefs.includes('add')) {
			setType('add')
		} else {
			setType('edit')
		}
	}, [])

	const customizeHeader = (value: string) => (
		<div>
			<div className={styles.tip} />
			{value}
		</div>
	)
	const onSave = async () => {
		const biddingDocumentUrl = fileList?.map(
			(item) => item?.response?.data?.id || item?.uid,
		)
		let newData: any = {}
		const projectValue = await projectForm.validateFields()
		const BidEvaluationVlaue = await bidEvaluationForm.validateFields()
		const calibrationValue = await calibrationForm.validateFields()
		const accountValue = await accountForm.validateFields()
		const bidAbandonmentValue = await bidAbandonmentForm.validateFields()

		if (
			projectValue &&
			BidEvaluationVlaue &&
			calibrationValue &&
			accountValue &&
			bidAbandonmentValue
		) {
			newData = {
				...projectValue,
				...BidEvaluationVlaue,
				...calibrationValue,
				...accountValue,
				...bidAbandonmentValue,
				...urlData,
				biddingDocumentUrl: biddingDocumentUrl?.toString(),
			}
		}
		if (newData) {
			setFormData({
				...newData,
				bidWinningSecurity: newData?.bidWinningSecurity
					? newData?.bidWinningSecurity
					: 0,
				bidWinningServiceFee: newData?.bidWinningServiceFee
					? newData?.bidWinningServiceFee
					: 0,
				createArchivesTime: moment(
					projectValue?.createArchivesTime,
				).format('YYYY-MM-DD HH:mm'),
				bidOpeningTime: moment(projectValue?.bidOpeningTime).format(
					'YYYY-MM-DD HH:mm',
				),
				bidWinningIssueDate: moment(
					calibrationValue?.bidWinningIssueDate,
				).format('YYYY-MM-DD HH:mm'),
				bidEvaluationTime: moment(
					bidAbandonmentValue?.bidEvaluationTime,
				).format('YYYY-MM-DD HH:mm'),
				isDraft: 2,
				answerList: answerData,
				recordList: bidOpeningData,
			})
			setDraftType(false)
			if (!urlData?.biddingNoticeUrl) {
				message.warning('请上传招标公告')
			} else if (!urlData?.changeNoticeUrl) {
				message.warning('请上传变更公告')
			} else if (!urlData?.delayNoticeUrl) {
				message.warning('请上传延期公告')
			}
			if (
				urlData?.biddingNoticeUrl &&
				urlData?.changeNoticeUrl &&
				urlData?.delayNoticeUrl
			) {
				setIsModalOpen(true)
			}
		}
	}
	const submit = async () => {
		let request: any
		setBtnLoading(true)
		if (query?.id) {
			// 编辑
			request = editSupplierbidding({
				...formData,
				...departmentData,
				id: query.id,
			})
		} else {
			request = addSupplierbidding(formData)
		}
		request
			.then((res: any) => {
				if (res.success) {
					message.success(res.msg)
					history.goBack()
					setBtnLoading(false)
				} else {
					setBtnLoading(false)
				}
			})
			.catch((err: any) => {
				message.error(err)
				setBtnLoading(false)
			})
	}
	/** 存草稿 */
	const onDraft = (e: {stopPropagation: () => void}) => {
		e.stopPropagation()
		const projectValue = projectForm.getFieldsValue()
		const biddingDocumentUrl = fileList?.map(
			(item) => item?.response?.data?.id || item?.uid,
		)
		setFormData({
			...projectValue,
			...urlData,
			isDraft: 1,
			biddingDocumentUrl: biddingDocumentUrl?.toString() || '',
			createArchivesTime: projectValue?.createArchivesTime
				? moment(projectValue?.createArchivesTime).format(
						'YYYY-MM-DD HH:mm',
				  )
				: '',
			bidOpeningTime: projectValue?.bidOpeningTime
				? moment(projectValue?.bidOpeningTime).format(
						'YYYY-MM-DD HH:mm',
				  )
				: '',
		})
		setDraftType(true)
		setIsModalOpen(true)
	}

	const normFile = (e: any) => {
		if (Array.isArray(e)) {
			return e
		}
		if (e?.file?.status) {
			return e?.fileList
		}
		return null
	}
	const zbUploadProps = {
		action: uploadFileUrl,
		name: fileName,
		data: {
			modelName: 'spBidding',
			targetAttr: 1,
		},
		beforeUpload: (file: any) => {
			const sizeLimit = file.size / 1024 / 1024 < 200
			if (!sizeLimit) {
				message.warning('文件必须小于200MB')
			}
			return sizeLimit
		},
		onChange(info: any) {
			if (info?.file?.status) {
				setFileList(info?.fileList)
			}
			if (info.file.status === 'done') {
				setFileList(info?.fileList)
			}
		},
		fileList,
	}

	const uploadDom = (targetAttr: number, name: string) => {
		const uploadProps: any = {
			key: targetAttr,
			modelName: 'spBidding',
			targetAttr,
			callback: (key: string) => {
				callBack(name, key)
			},
		}
		if (type !== 'add') {
			const newData = enclosureList?.find(
				(item: {targetAttr: number}) => item?.targetAttr === targetAttr,
			)
			if (newData) {
				uploadProps.fileList = [
					{
						uid: newData?.targetAttr?.toString(),
						name: newData?.filename,
						url: newData?.url,
					},
				]
			}
		}
		return (
			<>
				<CustomUpload {...uploadProps} />{' '}
			</>
		)
	}

	return (
		<Spin spinning={loading}>
			<div className={styles.admittanceAdd}>
				<div className={`${styles.content} ${common.formDetils}`}>
					<Collapse
						collapsible="header"
						defaultActiveKey={
							type === 'view'
								? ['1']
								: ['1', '2', '3', '4', '5', '6', '7', '8']
						}
						ghost
						expandIconPosition="end">
						<Panel
							header={
								<>
									<div>
										<div className={styles.tip} />
										招标项目
										{projectStatus === '1' &&
										type !== 'view' ? (
											<Button
												onClick={onDraft}
												style={{marginLeft: '12px'}}
												size="small">
												存草稿
											</Button>
										) : (
											''
										)}
									</div>
								</>
							}
							key="1">
							<Form
								form={projectForm}
								name="basic"
								layout="horizontal"
								labelCol={{flex: '160px'}}
								labelAlign="right"
								labelWrap
								autoComplete="off"
								disabled={type === 'view'}>
								<Form.Item
									label="招标编号"
									name="biddingCode"
									hidden>
									<Input
										placeholder={
											type === 'view' ? '-' : '请输入'
										}
									/>
								</Form.Item>
								<Row gutter={12}>
									<Col
										sm={{span: 24}}
										md={{span: 12}}
										lg={{span: 8}}>
										<Form.Item
											label="项目状态"
											name="projectStatus"
											rules={[{required: true}]}>
											<Select
												onChange={(value) => {
													setProjectStatus(value)
												}}
												placeholder={
													type === 'view'
														? '-'
														: '请选择'
												}
												fieldNames={{
													value: 'dictKey',
													label: 'dictValue',
												}}
												options={
													dictData?.Project_Status
												}
											/>
										</Form.Item>
									</Col>
									<Col
										sm={{span: 24}}
										md={{span: 12}}
										lg={{span: 8}}>
										<Form.Item
											label="项目标段"
											name="projectBidSection"
											rules={[{required: true}]}>
											<Select
												placeholder={
													type === 'view'
														? '-'
														: '请选择'
												}
												allowClear
												fieldNames={{
													value: 'dictKey',
													label: 'dictValue',
												}}
												options={
													dictData?.Project_Bid_Section
												}
											/>
										</Form.Item>
									</Col>
									<Col
										sm={{span: 24}}
										md={{span: 12}}
										lg={{span: 8}}>
										<Form.Item
											label="建档人"
											name="createArchivesPerson"
											rules={[
												{
													required: true,
												},
											]}>
											<Input
												placeholder={
													type === 'view'
														? '-'
														: '请输入'
												}
												disabled
											/>
										</Form.Item>
									</Col>
									<Col
										sm={{span: 24}}
										md={{span: 12}}
										lg={{span: 8}}>
										<Form.Item
											label="建档时间"
											name="createArchivesTime"
											rules={[{required: true}]}>
											<DatePicker
												placeholder={
													type === 'view'
														? '-'
														: '请选择'
												}
												showTime
												format="YYYY-MM-DD HH:mm"
											/>
										</Form.Item>
									</Col>
									<Col
										sm={{span: 24}}
										md={{span: 12}}
										lg={{span: 8}}>
										<Form.Item
											label="项目名称"
											name="projectName"
											rules={[
												{
													required: true,
													max: 30,
												},
											]}>
											<Input
												placeholder={
													type === 'view'
														? '-'
														: '请输入'
												}
											/>
										</Form.Item>
									</Col>
									<Col
										sm={{span: 24}}
										md={{span: 12}}
										lg={{span: 8}}>
										<Form.Item
											label="主导部门"
											name="leadingDeptId"
											rules={[{required: true}]}>
											<TreeSelect
												showSearch
												style={{width: '100%'}}
												dropdownStyle={{
													maxHeight: 400,
													overflow: 'auto',
												}}
												treeNodeFilterProp="name"
												placeholder={
													type === 'view'
														? '-'
														: '请选择'
												}
												allowClear
												treeDefaultExpandAll
												fieldNames={fieldNames}
												treeData={deptSource}
												onChange={(value) => {
													setDepartmentData({
														...departmentData,
														leadingDeptId: value,
													})
												}}
											/>
										</Form.Item>
									</Col>
									<Col
										sm={{span: 24}}
										md={{span: 12}}
										lg={{span: 8}}>
										<Form.Item
											label="采购部门"
											name="purchaseDeptId"
											rules={[{required: true}]}>
											<TreeSelect
												showSearch
												style={{width: '100%'}}
												dropdownStyle={{
													maxHeight: 400,
													overflow: 'auto',
												}}
												treeNodeFilterProp="name"
												placeholder={
													type === 'view'
														? '-'
														: '请选择'
												}
												allowClear
												treeDefaultExpandAll
												fieldNames={fieldNames}
												treeData={deptSource}
												onChange={(value) => {
													setDepartmentData({
														...departmentData,
														purchaseDeptId: value,
													})
												}}
											/>
										</Form.Item>
									</Col>
									<Col
										sm={{span: 24}}
										md={{span: 12}}
										lg={{span: 8}}>
										<Form.Item
											label="项目预算"
											name="projectBudget"
											rules={[
												{
													required: true,
												},
												{
													pattern:
														/^([0-9]|[1-9]\d+)(\.\d{0,2})?$/,
													message:
														'小数点后不得超过两位',
												},
											]}>
											<InputNumber
												max={1000000000}
												formatter={(value) => {
													if (type === 'view') {
														return `${value}万元`
													}
													return (
														value?.toString() || ''
													)
												}}
												addonAfter="万元"
												placeholder={
													type === 'view'
														? '-'
														: '请输入'
												}
											/>
										</Form.Item>
									</Col>
									<Col
										sm={{span: 24}}
										md={{span: 12}}
										lg={{span: 8}}>
										<Form.Item
											label="开标时间"
											name="bidOpeningTime"
											rules={[{required: true}]}>
											<DatePicker
												placeholder={
													type === 'view'
														? '-'
														: '请选择'
												}
												showTime
												format="YYYY-MM-DD HH:mm"
											/>
										</Form.Item>
									</Col>
									<Col
										sm={{span: 24}}
										md={{span: 12}}
										lg={{span: 8}}>
										<Form.Item
											label="开标地点"
											name="bidOpeningAddress"
											rules={[{max: 30}]}>
											<Input
												placeholder={
													type === 'view'
														? '-'
														: '请输入'
												}
											/>
										</Form.Item>
									</Col>
									<Col
										sm={{span: 24}}
										md={{span: 12}}
										lg={{span: 12}}
										className={styles.biddingDocumentUrl}>
										<Form.Item
											name="biddingDocumentUrl"
											label="招标文件上传"
											valuePropName="fileList"
											getValueFromEvent={normFile}
											rules={[
												{
													required: true,
													message: '请上传招标文件',
												},
											]}
											className={styles.fileUpload}>
											<Upload {...zbUploadProps}>
												{fileList.length >= 5 ? null : (
													<Button>请选择文件</Button>
												)}
											</Upload>
										</Form.Item>
										{/* <Button type="link">
											下载标书模版
										</Button> */}
									</Col>
								</Row>
								<table border="1" className={styles.uploadWrap}>
									<tr>
										<td className={styles.required}>
											招标公告
										</td>
										<td>
											{uploadDom(2, 'biddingNoticeUrl')}
										</td>
										<td className={styles.required}>
											变更公告
										</td>
										<td>
											{uploadDom(3, 'changeNoticeUrl')}
										</td>
										<td className={styles.required}>
											延期公告
										</td>
										<td>
											{uploadDom(4, 'delayNoticeUrl')}
										</td>
									</tr>
									<tr>
										<td colSpan={6}>
											<OtherUpload
												uploadType="DDUpload"
												urlName="biddingOtherUrl"
												targetAttr={5}
												fileList={otherFileList}
												setFileList={setOtherFileList}
												urlData={urlData}
												setUrlData={setUrlData}
											/>
										</td>
									</tr>
								</table>
							</Form>
						</Panel>
						{['3', '4', '5', '6', '7', '8'].includes(
							projectStatus,
						) ? (
							<Panel header={customizeHeader('投标应答')} key="2">
								<Answer
									type={type}
									dictData={dictData}
									answerData={answerData}
									setAnswerData={setAnswerData}
								/>
							</Panel>
						) : (
							''
						)}
						{['4', '5', '6', '8'].includes(projectStatus) ? (
							<Panel header={customizeHeader('开标记录')} key="3">
								<BidOpeningRecord
									type={type}
									answerData={answerData}
									bidOpeningData={bidOpeningData}
									setBidOpeningData={setBidOpeningData}
									dictData={dictData}
								/>
							</Panel>
						) : (
							''
						)}
						{['4', '5', '6', '8'].includes(projectStatus) ? (
							<Panel header={customizeHeader('评标情况')} key="4">
								<Form
									form={bidEvaluationForm}
									name="basic"
									layout="horizontal"
									labelCol={{flex: '160px'}}
									labelAlign="right"
									labelWrap
									autoComplete="off"
									disabled={type === 'view'}>
									<Row gutter={12}>
										<Col
											sm={{span: 24}}
											md={{span: 12}}
											lg={{span: 8}}>
											<Form.Item
												label="评标时间"
												name="bidEvaluationTime"
												rules={[{required: true}]}>
												<DatePicker
													placeholder={
														type === 'view'
															? '-'
															: '请选择'
													}
													showTime
													format="YYYY-MM-DD HH:mm"
												/>
											</Form.Item>
										</Col>
										<Col
											sm={{span: 24}}
											md={{span: 12}}
											lg={{span: 8}}>
											<Form.Item
												label="评审专家"
												name="reviewExpert"
												rules={[
													{
														required: true,
														max: 100,
													},
												]}>
												<Input
													onMouseOver={(e: any) => {
														e.target.title =
															e.target.value
													}}
													placeholder={
														type === 'view'
															? '-'
															: '请输入'
													}
												/>
											</Form.Item>
										</Col>
									</Row>
									<table
										border="1"
										className={styles.uploadWrap}>
										<tr>
											<td>综合打分表</td>
											<td>
												{uploadDom(
													6,
													'comprehensiveScoringUrl',
												)}
											</td>
											<td>标中质疑文件</td>
											<td>
												{uploadDom(
													7,
													'bidWinningDocumentUrl',
												)}
											</td>
											<td>评标报告</td>
											<td>
												{uploadDom(
													8,
													'bidEvaluationReport',
												)}
											</td>
										</tr>
										<tr>
											<td colSpan={6}>
												<OtherUpload
													uploadType="DDUpload"
													urlName="bidEvaluationUrl"
													targetAttr={9}
													fileList={
														otherEvaluationUrl
													}
													setFileList={
														setOtherEvaluationUrl
													}
													urlData={urlData}
													setUrlData={setUrlData}
												/>
											</td>
										</tr>
									</table>
								</Form>
							</Panel>
						) : (
							''
						)}
						{['5', '6', '8'].includes(projectStatus) ? (
							<Panel header={customizeHeader('定标情况')} key="5">
								<Form
									form={calibrationForm}
									name="basic"
									layout="horizontal"
									labelCol={{flex: '160px'}}
									labelAlign="right"
									labelWrap
									autoComplete="off"
									disabled={type === 'view'}>
									<Row gutter={12}>
										<Col
											sm={{span: 24}}
											md={{span: 12}}
											lg={{span: 8}}>
											<Form.Item
												label="中标供应商"
												name="bidWinningSupplierId"
												rules={[{required: true}]}>
												<Select
													placeholder={
														type === 'view'
															? '-'
															: '请选择'
													}
													allowClear
													fieldNames={{
														value: 'supplierCode',
														label: 'supplierName',
													}}
													options={bidOpeningData}
													onChange={(value) => {
														bidAbandonmentForm.setFieldsValue(
															{
																bidAbandonmentSupplierId:
																	value,
															},
														)
													}}
												/>
											</Form.Item>
										</Col>
										<Col
											sm={{span: 24}}
											md={{span: 12}}
											lg={{span: 8}}>
											<Form.Item
												label="中标金额"
												name="bidWinningAmount"
												rules={[
													{required: true},
													{
														pattern:
															/^([0-9]|[1-9]\d+)(\.\d{0,2})?$/,
														message:
															'小数点后不得超过两位',
													},
												]}>
												<InputNumber
													max={1000000000}
													formatter={(value) => {
														if (type === 'view') {
															return `${value}万元`
														}
														return (
															value?.toString() ||
															''
														)
													}}
													addonAfter="万元"
													placeholder={
														type === 'view'
															? '-'
															: '请输入'
													}
												/>
											</Form.Item>
										</Col>
										<Col
											sm={{span: 24}}
											md={{span: 12}}
											lg={{span: 8}}>
											<Form.Item
												label="中标服务费"
												name="bidWinningServiceFee"
												rules={[
													{
														pattern:
															/^([0-9]|[1-9]\d+)(\.\d{0,2})?$/,
														message:
															'小数点后不得超过两位',
													},
												]}>
												<InputNumber
													max={1000000000}
													formatter={(value) => {
														if (type === 'view') {
															return `${value}万元`
														}
														return (
															value?.toString() ||
															''
														)
													}}
													addonAfter="万元"
													placeholder={
														type === 'view'
															? '-'
															: '请输入'
													}
												/>
											</Form.Item>
										</Col>
										<Col
											sm={{span: 24}}
											md={{span: 12}}
											lg={{span: 8}}>
											<Form.Item
												label="中标保证金"
												name="bidWinningSecurity"
												rules={[
													{
														pattern:
															/^([0-9]|[1-9]\d+)(\.\d{0,2})?$/,
														message:
															'小数点后不得超过两位',
													},
												]}>
												<InputNumber
													max={1000000000}
													formatter={(value) => {
														if (type === 'view') {
															return `${value}万元`
														}
														return (
															value?.toString() ||
															''
														)
													}}
													addonAfter="万元"
													placeholder={
														type === 'view'
															? '-'
															: '请输入'
													}
												/>
											</Form.Item>
										</Col>
										<Col
											sm={{span: 24}}
											md={{span: 12}}
											lg={{span: 8}}>
											<Form.Item
												label="中标通知书发出日期"
												name="bidWinningIssueDate"
												rules={[{required: true}]}>
												<DatePicker
													placeholder={
														type === 'view'
															? '-'
															: '请选择'
													}
													showTime
													format="YYYY-MM-DD HH:mm"
												/>
											</Form.Item>
										</Col>
									</Row>
									<table
										border="1"
										className={styles.uploadWrap}>
										<tr>
											<td style={{width: '160px'}}>
												中标通知书
											</td>
											<td>
												{uploadDom(
													10,
													'bidWinningNoticeUrl',
												)}
											</td>
											<td style={{width: '160px'}}>
												中标候选人公示
											</td>
											<td>
												{uploadDom(
													11,
													'bidWinningCandidatesUrl',
												)}
											</td>
											<td style={{width: '160px'}}>
												中标结果公告
											</td>
											<td>
												{uploadDom(
													12,
													'bidWinningResultUrl',
												)}
											</td>
										</tr>
										<tr>
											<td colSpan={6}>
												<OtherUpload
													uploadType="DDUpload"
													urlName="bidWinningOtherUrl"
													targetAttr={13}
													fileList={otherWinningUrl}
													setFileList={
														setOtherWinningUrl
													}
													urlData={urlData}
													setUrlData={setUrlData}
												/>
											</td>
										</tr>
									</table>
								</Form>
							</Panel>
						) : (
							''
						)}
						{['6', '8'].includes(projectStatus) ? (
							<Panel
								header={customizeHeader('保证金退还账户')}
								key="6">
								<Form
									form={accountForm}
									name="basic"
									layout="horizontal"
									labelCol={{flex: '160px'}}
									labelAlign="right"
									labelWrap
									autoComplete="off"
									disabled={type === 'view'}>
									<Row gutter={12}>
										<Col
											sm={{span: 24}}
											md={{span: 12}}
											lg={{span: 8}}>
											<Form.Item
												label="开户银行"
												name="accountOpeningBank"
												rules={[
													{required: true, max: 20},
													{
														pattern:
															/^[\u4e00-\u9fa5]{0,}$/,
														message:
															'开户银行只能输入文字',
													},
												]}>
												<Input
													placeholder={
														type === 'view'
															? '-'
															: '请输入'
													}
												/>
											</Form.Item>
										</Col>
										<Col
											sm={{span: 24}}
											md={{span: 12}}
											lg={{span: 8}}>
											<Form.Item
												label="开户账号"
												name="accountNo"
												rules={[
													{required: true, max: 20},
													{
														pattern: /^[0-9]*$/,
														message:
															'开户账号只能输入纯数字',
													},
												]}>
												<Input
													placeholder={
														type === 'view'
															? '-'
															: '请输入'
													}
												/>
											</Form.Item>
										</Col>
										<Col
											sm={{span: 24}}
											md={{span: 12}}
											lg={{span: 8}}>
											<Form.Item
												label="开户行名称"
												name="openingBankName"
												rules={[
													{required: true},
													{
														pattern:
															/^[\u4e00-\u9fa5]{0,}$/,
														message:
															'开户行名称只能输入文字',
													},
												]}>
												<Input
													placeholder={
														type === 'view'
															? '-'
															: '请输入'
													}
												/>
											</Form.Item>
										</Col>
									</Row>
								</Form>
							</Panel>
						) : (
							''
						)}
						{['7', '8'].includes(projectStatus) ? (
							<Panel
								header={customizeHeader(
									projectStatus === '8'
										? '弃标情况'
										: '废标情况',
								)}
								key="7">
								<Form
									form={bidAbandonmentForm}
									name="basic"
									layout="horizontal"
									labelCol={{flex: '160px'}}
									labelAlign="right"
									labelWrap
									autoComplete="off"
									disabled={type === 'view'}>
									<Row gutter={12}>
										<Col
											sm={{span: 24}}
											md={{span: 12}}
											lg={{span: 8}}>
											<Form.Item
												label="异常类型"
												name="exceptionType">
												<Select
													placeholder={
														type === 'view'
															? '-'
															: '请选择'
													}
													disabled>
													<Option value={1}>
														废标
													</Option>
													<Option value={2}>
														弃标
													</Option>
												</Select>
											</Form.Item>
										</Col>
										{projectStatus === '8' ? (
											<Col
												sm={{span: 24}}
												md={{span: 12}}
												lg={{span: 8}}>
												<Form.Item
													label="弃标供应商"
													name="bidAbandonmentSupplierId">
													<Select
														placeholder={
															type === 'view'
																? '-'
																: '请选择'
														}
														fieldNames={{
															value: 'supplierCode',
															label: 'supplierName',
														}}
														options={bidOpeningData}
														disabled
													/>
												</Form.Item>
											</Col>
										) : (
											''
										)}
										<Col span={24}>
											<Form.Item
												label="异常原因"
												name="abnormalCauses"
												rules={[{required: true}]}>
												<TextArea
													maxLength={200}
													placeholder={
														type === 'view'
															? '-'
															: '请输入（最多200个字）'
													}
													autoSize={{
														minRows: 2,
														maxRows: 3,
													}}
												/>
											</Form.Item>
										</Col>
									</Row>
								</Form>
							</Panel>
						) : (
							''
						)}
						{type === 'view' ? (
							<Panel
								header={customizeHeader('操作记录')}
								key="8"
								forceRender>
								<OperationRecord
									businessId={query?.id}
									businessType={7}
								/>
							</Panel>
						) : (
							''
						)}
					</Collapse>
					<div className={styles.wrap}>
						{type !== 'view' ? (
							<>
								<Button
									type="primary"
									htmlType="submit"
									onClick={() => {
										onSave()
									}}>
									保存
								</Button>
								<Button
									onClick={() => {
										history.go(-1)
									}}>
									取消
								</Button>
							</>
						) : (
							''
						)}
						{type === 'view' ? (
							<Button
								onClick={() => {
									history.go(-1)
								}}>
								返回
							</Button>
						) : (
							''
						)}
					</div>
				</div>
				<Modal
					text={
						draftType
							? '确定要保存吗？保存后为草稿状态'
							: '确定要保存吗？请仔细核对所填信息'
					}
					loading={btnLoading}
					onSubmit={submit}
					isModalOpen={isModalOpen}
					setIsModalOpen={setIsModalOpen}
				/>
			</div>
		</Spin>
	)
}
export default connect(({user}: any) => ({user}))(add)
